package com.atguigu.atcrowdfunding.controller;

import com.atguigu.atcrowdfunding.bean.TMenu;
import com.atguigu.atcrowdfunding.service.TMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class TMenuController {

    @Autowired
    TMenuService menuService;

    @ResponseBody
    @RequestMapping("/menu/doDelete")
    public String doDelete(Integer id){
        menuService.deleteTMenu(id);
        return "ok";

    }

    @ResponseBody
    @RequestMapping("/menu/doUpdate")
    public String doUpdate(TMenu menu){
        menuService.updateTMenu(menu);
        return "ok";

    }


    @ResponseBody
    @RequestMapping("/menu/getMenuById")
    public TMenu getMenuById(Integer id){
       TMenu menu = menuService.getMenuById(id);
        return menu;
    }


    @RequestMapping("/menu/index")
    public String index(){
        return "menu/index";
    }

    @ResponseBody
    @RequestMapping("/menu/loadTree")
    public List<TMenu> loadTree(){
        List<TMenu> list = menuService.listMenuAllTree();
        return list;

    }

    @ResponseBody
    @RequestMapping("/menu/doAdd")
    public String doAdd(TMenu menu){
      menuService.saveTMenu(menu);
        return "ok";

    }




}
